<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        // let arr = [1, 2, 3]
        // let a = arr[0]
        // let b = arr[1]
        // let c = arr[2]

        let [a, b, c]  =  [1, 2, 3]
        console.log(a, b, c)

        let [m, n, [i, j]] = [1, 2, [3, 4]]
        console.log(m, n, i, j)

        // 忽略某个元素 用,隔开
        let [name1, ,name2] = ["孙悟空", "猪八戒", "大闸蟹"]
        console.log(name1, name2);

        // 变量的交换
        let str1 = "香蕉";
        let str2 = "草莓";

        [str1, str2] = [str2, str1]
        console.log(str1, str2)

        // 剩余/扩展运算符  ...
        // 剩余运算符
        let [name, ...reset] = ["孙悟空","猪八戒", "唐僧", "白龙马"]
        console.log(name, reset)//孙悟空 (3) ['猪八戒', '唐僧', '白龙马']

        // 扩展运算符
        let res = ["牛魔王", "白骨精"]
        let arr3 = ["铁扇公主", "红孩儿", ...res, ...reset]//['铁扇公主', '红孩儿', '牛魔王', '白骨精', '猪八戒', '唐僧', '白龙马']
        console.log(arr3)

    </script>
</body>
</html>